import comfig from "./comfig"
//封装 wx 的请求
export default function request(url, data, method = "GET") {
  return new Promise((resolve, reject) => {
    wx.request({
      url: comfig.moblieHost + url,
      data,
      method,
      header: {
        // 请求时本地的cookies
        cookie: wx.getStorageSync('cookies') && wx.getStorageSync('cookies').join(';')
      },
      success: (result) => {
        //登陆的时候，将cookies存储到本地
        if (data.isLogin) {
          wx.setStorageSync('cookies', result.cookies)
        }
        resolve(result.data)
      },
      fail: (err) => {
        reject(err)
      },
    })
  })
}